let fs = require('fs');

let path = __dirname;
let self = __filename.substring(__dirname.length + 1);


console.log(">>>>path",path);
let files = fs.readdirSync(path);
console.log(">>>>file",files);
files.forEach(function(filename) {
    if(filename == self)
        return;
    let pos = filename.lastIndexOf('.');
    if(pos == -1)
        return;
    let filePrefix = filename.substr(0, pos);
    let filePostfix = filename.substr(pos + 1);
    if(filePrefix.length < 1 || filePostfix.length < 1 || filePostfix != 'js')
        return;
    //加载所有的文件
    let model = require(path + '/' + filePrefix);

    // 装载文件所有方法
    Object.keys(model).forEach(function(key) {
        if(key != key.toLowerCase())
            return;
        let method = model[key];
        console.log(">>>>method",method);
        if(typeof method == 'function') {
            if(exports[key])
                throw new Error('Repeated method name: ' + key + ' in file: ' + filename);
            exports[key] = method;
        }
    });
});